package controleur;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modele.Competition;
import modele.FacadeSite;

/**
 * Servlet implementation class Ressources
 */
public class Ressources extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@EJB FacadeSite fs;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Ressources() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String ressource=request.getParameter("ressource");
		
		if(ressource.equals("listeCompetition")){
			String idSport=request.getParameter("idSport");
			
			try{
				long id = Long.valueOf(idSport);
				List<Competition> competitions = fs.getCompetitions(id);
				request.setAttribute("competitions", competitions);
				
				request.getRequestDispatcher("listeCompetition.jsp").forward(request, response);
				
				
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
